package test.com.linkgie.galaxyframework.httpproxy.core;

import com.linkgie.galaxyframework.httpproxy.ResponseHandler;
import com.linkgie.galaxyframework.httpproxy.ServiceInvocationContext;
import com.linkgie.galaxyframework.httpproxy.ServiceResponse;
import com.linkgie.galaxyframework.httpproxy.converters.JsonResponseHandler;

public class GetContentResponseHandlerWithException implements ResponseHandler {

	private JsonResponseHandler jsonResponseHandler = new JsonResponseHandler(DataResponse.class);

	@Override
	public Object handleResponse(com.linkgie.galaxyframework.httpproxy.ServiceRequest request, ServiceResponse response,
			ServiceInvocationContext serviceContext) throws Exception {
		DataResponse data = (DataResponse) jsonResponseHandler.handleResponse(request, response, serviceContext);
		if (data.isSuccess()) {
			return data.getContent();
		}
		throw new GetContentException(data.getError());
	}

}
